package com.subway.babynote;
/*水*/
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.TimeZone;

import com.subway.babynote.syncdata.ClientDataRecord.contactRecord;
import com.subway.babynote.syncdata.ClientDataRecord.last_avgRecord;
import com.subway.babynote.syncdata.StringUtil;
import com.subway.babynote.syncservice.syncapi;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.database.Cursor;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

public class comparefeed extends Activity {
	private static final int INVISIBLE = 0x00000004;
	TextView userage_view;
	int today;
	String[] from;
	int[] to;
	ListView lv;
	SimpleAdapter mAdapter;
	Cursor cur;
	NotedbHelper notedb;
    Date date;
    Intent In;
    Button login_button;
    private LinearLayout linearLayout, statistics, sync, more;
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.comparefeed);
		setTitle(R.string.comparewithothers);
		userage_view = (TextView) findViewById(R.id.userinfo_TextView);
		notedb = new NotedbHelper(this);
		lv = (ListView) findViewById(R.id.compare_list);
		In = new Intent();
		//initTabFunction();
		
		login_button = (Button) findViewById(R.id.login_button);
		try {
			if(syncapi.getSyncImpl().getUserid()!= -1){
				login_button.setVisibility(INVISIBLE);
				login_button.setClickable(false);
			}
		//	cur = notedb.getAverage();
			List<last_avgRecord> lc=syncapi.getSyncImpl().getAverage();
			from = new String[] { "food_prop", "yours", "avgs", "diffs" };
			to = new int[] { R.id.item1, R.id.item2, R.id.item3, R.id.item4, };
			ArrayList<HashMap<String, Object>> feeds = new ArrayList<HashMap<String, Object>>();
			//while (!cur.isAfterLast()) {
			Iterator<last_avgRecord> it = lc.iterator();
			while(it.hasNext()){
				HashMap<String, Object> feed = new HashMap<String, Object>();
				feed.put("food_prop", cur.getString(1));
				feed.put("yours", cur.getString(2));
				feed.put("avgs", cur.getFloat(3));
				feed.put("diffs", cur.getFloat(4));
				feeds.add(feed);
				
			}
		
			
            
			mAdapter = new SimpleAdapter(this, feeds, R.layout.compare_item, from,
					to);
			
			lv.setAdapter(mAdapter);
			int age = syncapi.getSyncImpl().getUserAge();
			 
			if (!syncapi.getSyncImpl().getUserGender()) {
				userage_view.setText(getResources().getString(R.string.babygirl) + age + getResources().getString(R.string.monthold));
			} else {
				userage_view.setText(getResources().getString(R.string.babyboy) + age + getResources().getString(R.string.monthold));
			}
		} catch (Exception e) {
			Log.v("perdaystatistics", "from DB e=" + e.getMessage());
		}
		login_button.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {

				In.setClass(comparefeed.this, login.class);
				startActivity(In);
			}
		});

	}
	

	
	public void onDestroy(){
		   notedb.close();
		   super.onDestroy();	  	   
		   
		}

}